/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tabelmodel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Obat;

/**
 *
 * @author Asus
 */
public class ObatTableModel extends AbstractTableModel {

    private List<Obat> ob = new ArrayList<Obat>();

    public ObatTableModel(List<Obat> oo) {
        this.ob = oo;
    }

    public void deleteObat(int row){
        ob.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void updateObat(int row, Obat oo){
        ob.set(row,oo);
        fireTableRowsUpdated(row, row);
    }

    public void addObat(Obat oo) {
        ob.add(oo);
        fireTableRowsInserted(getRowCount() - 1, getColumnCount() - 1);
    }

    public int getRowCount() {
        return ob.size();
    }


    public int getColumnCount() {
        return 3;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Obat b = ob.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return b.getKodeObat();
            case 1:
                return b.getNamaObat();
            case 2:
                return b.getKategori().getKodeKategori() + " " + b.getKategori().getNamaKategori();
            default:
                return "";
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Kode Obat";
            case 1:
                return "Nama Obat";
            case 2:
                return "Kategori";
            default:
                return "";
        }
    }
}


